package com.iemes.controller.inventory;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.OrderFormMap;
import com.iemes.entity.inventory.PisFormMap;
import com.iemes.mapper.inventory.PutInStorageMapper;
import com.iemes.util.Common;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.inject.Inject;
import java.util.List;

//入库管理PutInStorage
@Controller
@RequestMapping("/PutInStorage/")
public class PutInStorageControllers extends BaseController {

    @Inject
    private PutInStorageMapper pis;

    @RequestMapping("pisIndex")
    public String index(Model model){
        String[] btnArray = new String[]{"<button type=\"button\" id=\"addAccount\" class=\"btn btn-primary marR10\">新增</button>", "<button type=\"button\" id=\"editAccount\" class=\"btn btn-info marR10\">编辑</button>", "<button type=\"button\" id=\"delAccount\" class=\"btn btn-danger marR10\">删除</button>"};
        model.addAttribute("res", findByRes());
        model.addAttribute("btn", btnArray);
        return Common.BACKGROUND_PATH + "/inventory/putinstorage/puinstorageIndex";
    }

    @ResponseBody
    @RequestMapping("getPisPage")
    public PageInfo getWorkOrderPage(){
        PageHelper.startPage(1, 10);
        List<PisFormMap> schedulingFormMaps = pis.getPisPage();
        PageInfo pageInfo = new PageInfo<>(schedulingFormMaps);
        return pageInfo;
    }

    @RequestMapping("openPisUI")
    public String openPisManagementUI(Model model){
        model.addAttribute("emp",getEmp());
        return Common.BACKGROUND_PATH + "/inventory/putinstorage/addpis";
    }

    @ResponseBody
    @RequestMapping("addPis")
    //    @SystemLog(module="系统管理",methods="客户管理-新增客户")//凡需要处理业务逻辑的.都需要记录操作日志
    @Transactional(readOnly=false)//需要事务操作必须加入此注解
    public String addPis(){
        PisFormMap pisFormMap = getFormMap(PisFormMap.class);
        int num = 0;
        num = num + pis.getPisPage().size();
        pisFormMap.set("wInId",num);
        pisFormMap.set("auditTime",pisFormMap.get("inTime"));
        pisFormMap.set("status",1);
        try {
            pis.addEntity(pisFormMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "success";
    }


}
